import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
// import eslintPlugin from "vite-plugin-eslint";
import {
  ElementPlusResolver,
  NaiveUiResolver,
} from "unplugin-vue-components/resolvers";
import { resolve } from "path";

const pathSrc = resolve(__dirname, "src");

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "@": pathSrc,
    },
  },
  plugins: [
    vue(),
    // vite构建是检查
    // eslintPlugin({
    //   include: ["src/**/*.ts", "src/**/*.vue", "src/*.ts", "src/*.vue"],
    // }),
    // 自动导入参考： https://github.com/sxzz/element-plus-best-practices/blob/main/vite.config.ts
    AutoImport({
      // 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
      resolvers: [ElementPlusResolver()],
      // 后续vue/vue-router/pinia的API都不需要再单独import到setup里面了
      imports: [
        "vue",
        "vue-router",
        "pinia",
        {
          "naive-ui": [
            "useDialog",
            "useMessage",
            "useNotification",
            "useLoadingBar",
          ],
        },
      ],
      // 可以自定义文件生成的位置与是否生成，默认是根目录下
      // dts: "src/auto-imports...",
      dts: false,
    }),
    Components({
      resolvers: [ElementPlusResolver(), NaiveUiResolver()],
      // 指定自定义组件位置(默认:src/components)
      // dirs: ["src/components"],
    }),
  ],
  optimizeDeps: {
    include: ["vue", "vue-router", "pinia", "axios"],
  },
});
